﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace QLNhaSach.Report
{
    public partial class SachForm : Form
    {
        public SachForm()
        {
            InitializeComponent();

        }

        private void SachForm_Load(object sender, EventArgs e)
        {
            ReportDocument cryRpt = new ReportDocument();
            string cwd = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string projectName = "QLNhaSach";
            string solutionPath = cwd.Replace(projectName + ".exe", "") + "\\Sach.rpt";
            cryRpt.Load(solutionPath);
            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            ReportDocument cryRpt = new ReportDocument();
            string cwd = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string projectName = "QLNhaSach";
            string solutionPath = cwd.Replace(projectName + ".exe", "") + "\\Sach.rpt";
            cryRpt.Load(solutionPath);
            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh();

            ParameterFieldDefinitions crParameterFieldDefinitions ;
            ParameterFieldDefinition crParameterFieldDefinition ;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value = Convert.ToInt32(textEdit1.Text);
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["DonGia"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh(); 
        }
    }
}
